using B.S.XZYData.Api.Read.Application.Command.Approval;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace B.S.XZYData.Api.Read.Controllers
{
    /// <summary>
    /// 审批查询接口
    /// </summary>
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class ApprovalController : ControllerBase
    {
        private readonly IMediator _mediator;

        public ApprovalController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 查询所有审批列表（包含所有状态）
        /// </summary>
        /// <param name="command">查询条件</param>
        /// <returns>审批分页数据</returns>
        [HttpGet]
        public async Task<IActionResult> GetPendingApprovals([FromQuery] QueryPendingApprovalsCommand command)
        {
            var result = await _mediator.Send(command);
            return Ok(result);
        }

        /// <summary>
        /// 查询我的申请记录
        /// </summary>
        /// <param name="command">查询条件</param>
        /// <returns>我的申请分页数据</returns>
        [HttpGet]
        public async Task<IActionResult> GetMyApplications([FromQuery] QueryMyApplicationsCommand command)
        {
            var result = await _mediator.Send(command);
            return Ok(result);
        }

        /// <summary>
        /// 查询审批详情
        /// </summary>
        /// <param name="workflowInstanceId">流程实例ID</param>
        /// <returns>审批详情数据</returns>
        [HttpGet]
        public async Task<IActionResult> GetApprovalDetail([FromQuery] int workflowInstanceId)
        {
            var command = new QueryApprovalDetailCommand
            {
                WorkflowInstanceId = workflowInstanceId
            };
            var result = await _mediator.Send(command);
            return Ok(result);
        }
    }
} 